package com.example.shoppingmall.cotroller;

import com.example.shoppingmall.config.MyLog;
import com.example.shoppingmall.pojo.Applet;
import com.example.shoppingmall.pojo.Official;
import com.example.shoppingmall.service.OfficialService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

@Controller
@RequestMapping("/official")
public class OfficialController {

    @Resource
    OfficialService officialService;


    @RequestMapping("/getOfficial")
    public String getOfficial(Model model) {
        model.addAttribute("official", officialService.getOfficial());
        return "/official/official";
    }

    @MyLog(value = "微信管理->公众号->修改")
    @RequestMapping("/updateOfficial")
    public String updateOfficial(Official official) {

        int num = officialService.update(official);
        if (num > 0) {
            return "redirect:/official/getOfficial";
        }
        return "/official/official";
    }

    @RequestMapping("/getApplet")
    public String getApplet(Model model) {
        model.addAttribute("applet", officialService.getApplet());
        return "/official/applet";
    }

    @MyLog(value = "微信管理->小程序->修改")
    @RequestMapping("/updateApplet")
    public String updateOfficial(Applet applet) {


        int num = officialService.updateApplet(applet);
        if (num > 0) {
            return "redirect:/official/getApplet";
        }
        return "/official/applet";
    }


}
